home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 676-700 / 681 / term / source.lha / termClip.c < prev    next >
C/C++ Source or Header  |  1992-05-09  |  2KB  |  115 lines

  1. /*
  2. **    $Id: termClip.c,v 1.1 92/04/03 20:43:08 olsen Sta Locker: olsen $
  3. **    $Revision: 1.1 $
  4. **    $Date: 92/04/03 20:43:08 $
  5. **
  6. **    Clipboard support routines
  7. **
  8. **    Copyright © 1990-1992 by Olaf `Olsen' Barthel & MXM
  9. **        All Rights Reserved
  10. */
  11.  
  12. #include "termGlobal.h"
  13.  
  14.     /* SaveClip(UBYTE *Buffer,LONG Size):
  15.      *
  16.      *    Send a given text buffer to the clipboard.
  17.      */
  18.  
  19. BYTE
  20. SaveClip(UBYTE *Buffer,LONG Size)
  21. {
  22.     BYTE Success = FALSE;
  23.  
  24.     if(Size > 0)
  25.     {
  26.         struct IFFHandle *Handle;
  27.  
  28.         if(Handle = AllocIFF())
  29.         {
  30.             if(Handle -> iff_Stream = (ULONG)OpenClipboard(PRIMARY_CLIP))
  31.             {
  32.                 InitIFFasClip(Handle);
  33.     
  34.                 if(!OpenIFF(Handle,IFFF_WRITE))
  35.                 {
  36.                     if(!PushChunk(Handle,'FTXT','FORM',IFFSIZE_UNKNOWN))
  37.                     {
  38.                         if(!PushChunk(Handle,0,'CHRS',IFFSIZE_UNKNOWN))
  39.                         {
  40.                             if(WriteChunkBytes(Handle,Buffer,Size) == Size)
  41.                             {
  42.                                 if(!PopChunk(Handle))
  43.                                     Success = TRUE;
  44.                             }
  45.                         }
  46.                     }
  47.  
  48.                     if(Success)
  49.                     {
  50.                         if(PopChunk(Handle))
  51.                             Success = FALSE;
  52.                     }
  53.  
  54.                     CloseIFF(Handle);
  55.                 }
  56.  
  57.                 CloseClipboard((struct ClipboardHandle *)Handle -> iff_Stream);
  58.             }
  59.  
  60.             FreeIFF(Handle);
  61.         }
  62.     }
  63.  
  64.     return(Success);
  65. }
  66.  
  67.     /* LoadClip(UBYTE *Buffer,LONG Size):
  68.      *
  69.      *    Put the contents of the clipboard into a given
  70.      *    buffer.
  71.      */
  72.  
  73. LONG
  74. LoadClip(UBYTE *Buffer,LONG Size)
  75. {
  76.     struct IFFHandle    *Handle;
  77.     LONG             Bytes = 0;
  78.  
  79.     if(Handle = AllocIFF())
  80.     {
  81.         if(Handle -> iff_Stream = (ULONG)OpenClipboard(PRIMARY_CLIP))
  82.         {
  83.             InitIFFasClip(Handle);
  84.  
  85.             if(!OpenIFF(Handle,IFFF_READ))
  86.             {
  87.                 if(!StopChunk(Handle,'FTXT','CHRS'))
  88.                 {
  89.                     if(!ParseIFF(Handle,IFFPARSE_SCAN))
  90.                     {
  91.                         struct ContextNode *ContextNode;
  92.  
  93.                         if(ContextNode = CurrentChunk(Handle))
  94.                         {
  95.                             if(Size > ContextNode -> cn_Size)
  96.                                 Size = ContextNode -> cn_Size;
  97.  
  98.                             if(ReadChunkRecords(Handle,Buffer,Size,1))
  99.                                 Bytes = Size;
  100.                         }
  101.                     }
  102.                 }
  103.  
  104.                 CloseIFF(Handle);
  105.             }
  106.  
  107.             CloseClipboard((struct ClipboardHandle *)Handle -> iff_Stream);
  108.         }
  109.  
  110.         FreeIFF(Handle);
  111.     }
  112.  
  113.     return(Bytes);
  114. }
  115.